package com.yyge.controller.mobile.orders;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yyge.common.util.WaimaiThreadLocal;
import com.yyge.common.vo.resp.R;
import com.yyge.entity.Orders;
import com.yyge.service.OrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "手机端-订单API")
@RequestMapping("/mobile/order")
@RestController
public class MobileOrdersController {

    @Autowired
    OrdersService ordersService;

    @ApiOperation(value = "最新的订单查询")
    @GetMapping
    public R getLastOrders(){
        Long id = WaimaiThreadLocal.getCurrent().getId();
        Orders orders = new Orders();
        orders.setUserId(id);
        orders.setUserName(WaimaiThreadLocal.getName());
        LambdaQueryWrapper wrapper=new LambdaQueryWrapper<>(orders);
        wrapper.orderByAsc("order_time");

        List list = ordersService.list(wrapper);
        if(list.size()>0){
            return R.okHasData(list.get(0));
        }
        return  R.ok();
    }

}
